package markgame2d.engine.mover;

import markgame2d.engine.interfaces.Moveable;

public class MarkConstantMoverByKeyboard implements MarkMover {

	private Moveable moveable;

	private float vLeft, vRight, vUp, vDown;
	private int leftKey, rightKey, upKey, downKey;

	private boolean[] keys;

	public MarkConstantMoverByKeyboard(Moveable moveable, float v, int leftKey,
			int rightKey, int upKey, int downKey, boolean[] keys) {
		this(moveable, v, v, v, v, leftKey, rightKey, upKey, downKey, keys);
	}

	public MarkConstantMoverByKeyboard(Moveable moveable, float vx, float vy,
			int leftKey, int rightKey, int upKey, int downKey, boolean[] keys) {
		this(moveable, vx, vx, vy, vy, leftKey, rightKey, upKey, downKey, keys);
	}

	public MarkConstantMoverByKeyboard(Moveable moveable, float vLeft,
			float vRight, float vUp, float vDown, int leftKey, int rightKey,
			int upKey, int downKey, boolean[] keys) {
		this.moveable = moveable;

		this.vLeft = vLeft;
		this.vRight = vRight;
		this.vUp = vUp;
		this.vDown = vDown;

		this.leftKey = leftKey;
		this.rightKey = rightKey;
		this.upKey = upKey;
		this.downKey = downKey;

		this.keys = keys;
	}

	public Moveable getMoveable() {
		return moveable;
	}

	public void setMoveable(Moveable moveable) {
		this.moveable = moveable;
	}

	public void move(float time) {

		float vx = 0;
		float vy = 0;

		if (keys[leftKey] & !keys[rightKey])
			vx = -vLeft;
		else if (keys[rightKey] & !keys[leftKey])
			vx = vRight;

		if (keys[upKey] & !keys[downKey])
			vy = -vUp;
		else if (keys[downKey] & !keys[upKey])
			vy = vDown;

		moveable.move(vx * time, vy * time);
	}

}
